import { getSupplyShopInfo } from '~/api/'
import cookieparser from 'cookieparser'
import Cookies from 'js-cookie'
import Hashes from 'jshashes'

const actions = {
  async nuxtServerInit ({state, commit}, {app, isDev, req, redirect}) {
      let accessToken = ''
      if (req.headers.cookie) {
        let cookie = cookieparser.parse(req.headers.cookie)
        // console.log('cookie:::::::::::::::::'+cookie)
        accessToken = cookie.accessToken
        // console.log('accessToken:::::::::::::::::'+accessToken)
      }
      if (accessToken !== '') {
        commit('TOGGLE_STATE', 'isLogin')
      }
  },  
  setLoginStatus ({ commit }, account = false) {
    commit('TOGGLE_STATE', 'isLogin')
    if (!account) {
      Cookies.remove('ACCESS_TOKEN')
    } else {
      let accessToken = new Hashes.MD5().hex(account)
      Cookies.set('ACCESS_TOKEN', accessToken, { expires: 1 })
    }
  }
}
export default actions
